package com.liu.communitysystemend.module.Repair.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.communitysystemend.module.repair.domain.Repair;
import com.liu.communitysystemend.module.repair.domain.RepairDto;
import com.liu.communitysystemend.module.repair.service.RepairService;
import com.liu.communitysystemend.module.repair.domain.Repair;
import com.liu.communitysystemend.module.repair.service.RepairService;
import com.liu.communitysystemend.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liu
 * @create 2023-03-02 10:51
 */
@RestController
@RequestMapping("/api/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;

    @ApiOperation("获取报修信息")
    @GetMapping("/get/{id}")
    public Result<Repair> getMenu(@PathVariable("id")String id){
        return Result.success(repairService.getRepairById(id));
    }

    @ApiOperation("更新报修信息")
    @PostMapping("modify")
    public Result<Repair> save(@RequestBody Repair repair) {
        return Result.success(repairService.update(repair));
    }

    @ApiOperation("添加报修信息")
    @PostMapping("add")
    public Result<Repair> add(@RequestBody Repair repair){
        return Result.success(repairService.add(repair));
    }

    @ApiOperation("查询报修列表(分页)")
    @PostMapping("page")
    public Result<Page<Repair>> getPage(@RequestBody Repair repair) {
        return Result.success(repairService.getPage(repair));
    }

    @ApiOperation("查询报修列表(分页)")
    @PostMapping("allPage")
    public Result<Page<RepairDto>> getAllPage(@RequestBody Repair repair) {
        return Result.success(repairService.getAllPage(repair));
    }


    @GetMapping("delete/{id}")
    @ApiOperation("删除报修")
    public Result deleteById(@PathVariable("id") String id) {
        return repairService.deleteById(id) > 0 ? Result.success() : Result.failed();
    }
    @GetMapping("/test")
    @ApiOperation("报修测试")
    public Result test() {
        return Result.success(repairService.test()) ;
    }
}

